package top.lunarye.handler.config;

import cn.hutool.core.thread.ExecutorBuilder;
import io.netty.util.concurrent.RejectedExecutionHandlers;
import top.lunarye.common.constant.ThreadPoolConstant;

import java.util.concurrent.*;

/**
 * handler线程池的配置
 * @author lunar
 * @since 2022-07-18
 */
public class HandlerThreadPoolConfig {
    private static final String PRE_FIX = "message";

    public static ExecutorService getExecutor(String groupId) {
        return ExecutorBuilder.create()
                .setCorePoolSize(ThreadPoolConstant.COMMON_CORE_POOL_SIZE)
                .setMaxPoolSize(ThreadPoolConstant.COMMON_MAX_POOL_SIZE)
                .setKeepAliveTime(ThreadPoolConstant.COMMON_KEEP_LIVE_TIME, TimeUnit.SECONDS)
                .setHandler(new ThreadPoolExecutor.CallerRunsPolicy())
                .setAllowCoreThreadTimeOut(false)
                .setWorkQueue(new LinkedBlockingQueue<>(ThreadPoolConstant.COMMON_QUEUE_SIZE))
                .build();

    }
}
